﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace System
{
    public partial class Window : Form
    {
        Graphics graphics;
        Bitmap bitmap;

        public Window(Core.EventMap em, Core.Database db)
        {
            InitializeComponent();
            database = db;
            this.Paint += new PaintEventHandler(Window_Paint);
        }

        void Window_Paint(object sender, PaintEventArgs ar)
        {
            graphics = Graphics.FromHwnd(this.Handle);
            foreach (Core.Edge e in database.Edges)
            {
                graphics.DrawLine(new Pen(Color.Black), new Point(e.node1.position.x, e.node1.position.y),
                                                        new Point(e.node2.position.x, e.node2.position.y));
                graphics.DrawString(e.distance.ToString(),
                                    new Font(FontFamily.GenericSerif, 10.0f), Brushes.Black,
                                    new PointF(e.node1.position.x + (e.node2.position.x - e.node1.position.x) / 2,
                                               e.node1.position.y + (e.node2.position.y - e.node1.position.y) / 2)
                                    );
            }
            foreach (Core.Node n in database.Nodes)
            {
                graphics.FillRectangle(Brushes.Black, new Rectangle(new Point(n.position.x - 30, n.position.y - 30), new Size(50, 50)));
                graphics.DrawString(n.id + ": " + n.distance.ToString(), new Font(FontFamily.GenericSerif, 10.0f), Brushes.White, new PointF(n.position.x - 20, n.position.y - 10));
            }
        }

        private Core.Database database;
    }
}
